/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Prototype;

import Model.Gates.*;
import Model.Inputs.*;

import Model.Main.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Pales
 */
public class InterCommands {

    public static void help() {
        print("addButton [name]\n");
        print("\t-Add Button to worksheet \n");
        print("addRategen [name]\n");
        print("\t-Add Rategenerator to worksheet \n");
        print("addGate [or/and] [no. of inputs] [name]\n");
        print("\t-Add AndGate or Orgate to worksheet \n");
        print("addInverter [name]\n");
        print("\t-Add Inverter to worksheet \n");
        print("addComposite [maxinput] [maxoutput] [name]\n");
        print("\t-Add Composite to worksheet \n");
        print("addGateToComp [composite] [or/and] [no. of inputs] [name]\n");
        print("\t-Ad Andgate or Orgate to one Composite \n");
        print("addInverterToComp [composite] [name]\n");
        print("\t-Add Inverter to Composite \n");
        print("addOscill [name]\n");
        print("\t-Add Oscilloscope to worksheet \n");
        print("addLed [name]\n");
        print("\t-Add Led to worksheet \n");
        print("setButton [name] [érték(0/1)] \n");
        print("\t-Set one button value \n");
        print("addWireGG [from] [fromnumber] [to] [tonumber] [name]\n");
        print("\t-Link two Gate with a Wire \n");
        print("addWireIG [from]  [to] [tonumber] [name]\n");
        print("\t-Link one Input and one Gate with a Wire \n");
        print("compAddWireIG [composite] [fromnumber] [to] [tonumber] [name]\n");
        print("\t-Link one Input and one Gate with a Wire in one Composite \n");
        print("compAddWireGG [composite] [from] [fromnumber] [to] [tonumber] [name]\n");
        print("\t-Link two Gate with a Wire in one Composite \n");
        print("compAddWireGO [composite] [from] [fromnumber] [tonumber] [name]\n");
        print("\t-Link one Output and one Gate with a Wire in one Composite \n");
        print("delete [name]\n");
        print("\t-Delete one Gate or Input from the worksheet \n");
        print("delWire [from Gate/Input] [name]\n");
        print("\t-Delete one Wire from the worksheet \n");
        print("step\n");
        print("\t-You can take ohne step one step on the moon on the moon on the moon \n");
        print("run [Number of steps]\n");
        print("\t-Simulate the modell\n");
        print("pause\n");
        print("\t-Pause the simulate \n");
        print("stop\n");
        print("\t-Stop the simulate\n");
        print("clean\n");
        print("\t-Clear the modell\n");
        print("loadFile [filepath]\n");
        print("\t-Load a commands from a file \n");
        print("getValue [name]\n");
        print("\t-Query a value\n");
        print("addChildWire [wire][to][toInput][name]\n");
        print("\t-Link a wire and a Gate\n");
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addOscill(ProtoController proto, String[] consoleComm) {
        if (consoleComm.length != 2) {
            print("usage: addOscill [name]\n");
            return;

        }


        Oscilloscope osc = new Oscilloscope(consoleComm[1]);

        proto.addGate(osc);
        proto.addNameBase(consoleComm[1], osc);

    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addGate(ProtoController proto, String[] consoleComm) {


        // print("Addgate command: ");
        try {
            if (consoleComm.length != 4 || Integer.valueOf(consoleComm[2]) <= 0) {
                print("usage: addGate [or/and] [no. of inputs] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: addGate [or/and] [no. of inputs] [name]\n");
            return;
        }

        try {
            if (consoleComm[1].equals("or")) {
                OrGate or = new OrGate(Integer.valueOf(consoleComm[2]), consoleComm[3]);
                or.setName(consoleComm[3]);
                proto.addGate(or);
                proto.addNameBase(consoleComm[3], or);

            } else {
                if (consoleComm[1].equals("and")) {
                    AndGate and = new AndGate(Integer.valueOf(consoleComm[2]), consoleComm[3]);
                    proto.addGate(and);
                    proto.addNameBase(consoleComm[3], and);
                } else {
                    print("Illegal argument \n");
                    print("usage: addGate [or/and] [no. of inputs] [name]\n");
                }
            }


        } catch (Exception e) {
            print("something went wrong: \n");
            e.printStackTrace();
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addGateToComp(ProtoController proto, String[] consoleComm) {
        // print("Addgate command: ");
        Composite comp;

        try {
            if (consoleComm.length != 5 || Integer.valueOf(consoleComm[3]) <= 0) {
                print("usage: addGateToComposite [composite] [or/and] [no. of inputs] [name]\n");
                return;
            }

        } catch (Exception e) {
            print("usage: addGateToComposite [composite] [or/and] [no. of inputs] [name]\n");
            return;
        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (consoleComm[2].equals("or")) {
                comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
                OrGate or = new OrGate(Integer.valueOf(consoleComm[3]), consoleComm[4]);
                proto.addGateComposite(comp, or);
                proto.addNameBase(consoleComm[4], or);

            } else {
                if (consoleComm[2].equals("and")) {
                    comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
                    AndGate and = new AndGate(Integer.valueOf(consoleComm[3]), consoleComm[4]);
                    proto.addGateComposite(comp, and);
                    proto.addNameBase(consoleComm[4], and);
                } else {
                    print("Illegal argument \n");
                    print("usage: addGateToComposite [composite] [or/and] [no. of inputs] [name]\n");
                }
            }


        } catch (Exception e) {
            print("something went wrong: \n");
            e.printStackTrace();
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addInverterToComp(ProtoController proto, String[] consoleComm) {
        Composite comp;
        if (consoleComm.length != 3) {
            print("usage: addInverterToComp [composite] [name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1) {
            print("Invalid Name\n");
            return;
        }

        Inverter inv = new Inverter(consoleComm[2]);
        comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
        proto.addGateComposite(comp, inv);
        proto.addNameBase(consoleComm[2], inv);

    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addLed(ProtoController proto, String[] consoleComm) {

        // print("AddLed command: ");
        if (consoleComm.length != 2) {
            print("usage: addLed [name]\n");
            return;

        }


        Led l = new Led(consoleComm[1]);

        proto.addGate(l);
        proto.addNameBase(consoleComm[1], l);

    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addButton(ProtoController proto, String[] consoleComm) {
        //print("addButton command:");
        if (consoleComm.length != 2) {
            print("usage: addButton [name]\n");
            return;

        }


        Button but = new Button(consoleComm[1]);

        proto.addInput(but);
        proto.addNameBase(consoleComm[1], but);
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addComposite(ProtoController proto, String[] consoleComm) {
        //print("addComposit command:");
        Composite comp;
        if (consoleComm.length != 4) {
            print("usage: addComposite [maxinput] [maxoutput] [name]\n");
            return;

        }
        try {
            if (Integer.valueOf(consoleComm[1]) < 0 | Integer.valueOf(consoleComm[2]) < 0) {
                print("usage: addComposite [maxinput] [maxoutput] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: addComposite [maxinput] [maxoutput] [name]\n");
            return;
        }



        comp = new Composite(Integer.valueOf(consoleComm[1]), Integer.valueOf(consoleComm[2]), consoleComm[3]);

        proto.addGate(comp);
        proto.addNameBase(consoleComm[3], comp);
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addInverter(ProtoController proto, String[] consoleComm) {
        // print("addinverter command:");
        if (consoleComm.length != 2) {
            print("usage: addInverter [name]\n");
            return;

        }


        Inverter inv = new Inverter(consoleComm[1]);

        proto.addGate(inv);
        proto.addNameBase(consoleComm[1], inv);
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addRategen(ProtoController proto, String[] consoleComm) {
        // print("addrategen command:");
        if (consoleComm.length != 2) {
            print("usage: addRategen [name]\n");
            return;

        }


        Rategen rat = new Rategen(consoleComm[1]);

        proto.addInput(rat);
        proto.addNameBase(consoleComm[1], rat);
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addChildWire(String[] consoleComm, ProtoController proto) {
        if (consoleComm.length != 5) {
            print("usage: addChildWire [wire][to][toInput][name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[2]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[3]) < 0) {
                print("usage: addChildWire [wire][to][toInput][name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: addChildWire [wire][to][toInput][name]\n");
            return;
        }
        Wire from = (Wire) proto.getObjectfromNameBase(consoleComm[1]);
        Gate to = (Gate) proto.getObjectfromNameBase(consoleComm[2]);
        Wire child = new Wire(to, Integer.valueOf(consoleComm[3]), consoleComm[4]);
        try {
            proto.addchildWire(child, from, to, Integer.valueOf(consoleComm[3]), consoleComm[4]);
        } catch (Exception ex) {
            print("Bad command \n");
        }

    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addWireGG(String[] consoleComm, ProtoController proto) {
        // print("addwireGG command:");
        Gate from;
        Gate to;
        if (consoleComm.length != 6) {
            print("usage: addWireGG [from] [fromnumber] [to] [tonumber] [name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[3]) == 1) {
            print("Invalid Name\n");
            return;
        }

        try {
            if (Integer.valueOf(consoleComm[2]) < 0 | Integer.valueOf(consoleComm[4]) < 0) {
                print("usage: addWireGG [from] [fromnumber] [to] [tonumber] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: addWireGG [from] [fromnumber] [to] [tonumber] [name]\n");
            return;
        }
        try {
            from = (Gate) proto.getObjectfromNameBase(consoleComm[1]);
            to = (Gate) proto.getObjectfromNameBase(consoleComm[3]);
        } catch (Exception ex) {
            print("Wrong Name");
            return;
        }

        proto.addWire(from, Integer.valueOf(consoleComm[2]), to, Integer.valueOf(consoleComm[4]), consoleComm[5]);
        try {
            proto.addNameBase(consoleComm[5], from.getWire(Integer.valueOf(consoleComm[2])));
        } catch (Exception e) {
            print(e.getMessage());
        }


    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void addWireIG(String[] consoleComm, ProtoController proto) {
        // print("addwireIG command:");
        Input from;
        Gate to;
        if (consoleComm.length != 5) {
            print("usage: addWireIG [from] [to] [tonumber] [name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[2]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[3]) < 0) {
                print("usage: addWireIG [from]  [to] [tonumber] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: addWireIG [from] [to] [tonumber] [name]\n");
            return;
        }
        try {
            from = (Input) proto.getObjectfromNameBase(consoleComm[1]);
            to = (Gate) proto.getObjectfromNameBase(consoleComm[2]);
        } catch (Exception ex) {
            print("Wrong Name");
            return;
        }

        proto.addWire(from, to, Integer.valueOf(consoleComm[3]), consoleComm[4]);
        proto.addNameBase(consoleComm[4], from.getWire());
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void compAddWireIG(String[] consoleComm, ProtoController proto) {
        Gate to;
        Composite comp;
        if (consoleComm.length != 6) {
            print("usage: compAddWireIG [Composite] [fromnumber] [to] [tonumber] [name]\n");
            return;
        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[3]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[2]) < 0 | Integer.valueOf(consoleComm[4]) < 0) {
                print("usage: compAddWireIG [Composite] [fromnumber] [to] [tonumber] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: compAddWireIG [Composite] [fromnumber] [to] [tonumber] [name]\n");
            return;
        }
        to = (Gate) proto.getObjectfromNameBase(consoleComm[3]);
        comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
        boolean in = false;
        for (int i = 0; i < comp.getCompSize(); i++) {
            if (to == comp.getCompGates(i)) {
                in = true;
                break;
            }
        }
        if (in == true) {
            try {
                proto.addWire(comp, Integer.valueOf(consoleComm[2]), to, Integer.valueOf(consoleComm[4]), consoleComm[5]);
                proto.addNameBase(consoleComm[5], comp.getCompInPort(Integer.valueOf(consoleComm[2])).getWire(0));
            } catch (Exception ex) {
                print(ex.getMessage());
                print("usage: compAddWireIG [Composite] [fromnumber] [to] [tonumber] [name]\n");
            }
        }

    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void compAddWireGG(String[] consoleComm, ProtoController proto) {
        Composite comp;
        Gate from;
        Gate to;
        if (consoleComm.length != 7) {
            print("usage: compAddWireGG [composite] [from] [fromnumber] [to] [tonumber] [name]\n");
            return;
        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[2]) == 1 | proto.nameIsInvalid(consoleComm[4]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[3]) < 0 | Integer.valueOf(consoleComm[5]) < 0) {
                print("usage: compAddWireGG [composite] [from] [fromnumber] [to] [tonumber] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: compAddWireGG [composite] [from] [fromnumber] [to] [tonumber] [name]\n");
            return;
        }
        comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
        from = (Gate) proto.getObjectfromNameBase(consoleComm[2]);
        to = (Gate) proto.getObjectfromNameBase(consoleComm[4]);

        Boolean notincomp1 = false;
        Boolean notincomp2 = false;
        for (int i = 0; i < comp.getCompSize(); i++) {
            if (comp.getCompGates(i) == from) {
                notincomp1 = true;
                break;

            }
        }
        for (int j = 0; j < comp.getCompSize(); j++) {
            if (comp.getCompGates(j) == to) {
                notincomp2 = true;
                break;
            }
        }
        if (notincomp1 == false) {
            print("This Gate :" + from.getName() + " isn't in this Composite");
        }
        if (notincomp2 == false) {
            print("This Gate :" + to.getName() + " isn't in this Composite");
        }
        if (notincomp1 && notincomp2) {
            proto.addWire(from, Integer.valueOf(consoleComm[3]), to, Integer.valueOf(consoleComm[5]), consoleComm[6]);
            try {
                proto.addNameBase(consoleComm[6], from.getWire(Integer.valueOf(consoleComm[3])));
            } catch (Exception e) {
                print(e.getMessage());
            }

        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void compAddWireGO(String[] consoleComm, ProtoController proto) {
        Gate from;
        Composite comp;

        if (consoleComm.length != 6) {
            print("usage: compAddWireGO [composite] [from] [fromnumber] [tonumber] [name]\n");
            return;
        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[2]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[3]) < 0 | Integer.valueOf(consoleComm[4]) < 0) {
                print("usage: compAddWireGO [composite] [from] [fromnumber] [tonumber] [name]\n");
                return;
            }
        } catch (Exception e) {
            print("usage: compAddWireGO [composite] [from] [fromnumber] [tonumber] [name]\n");
            return;
        }

        from = (Gate) proto.getObjectfromNameBase(consoleComm[2]);
        comp = (Composite) proto.getObjectfromNameBase(consoleComm[1]);
        boolean in = false;
        for (int i = 0; i < comp.getCompSize(); i++) {
            if (from == comp.getCompGates(i)) {
                in = true;
                break;
            }
        }
        if (in == true) {
            try {
                proto.addWire(comp, from, Integer.valueOf(consoleComm[3]), Integer.valueOf(consoleComm[4]), consoleComm[5]);
                proto.addNameBase(consoleComm[5], from.getWire(Integer.valueOf(consoleComm[3])));
            } catch (Exception ex) {
                print(ex.getMessage());
                print("usage: compAddWireGO [composite] [from] [fromnumber] [tonumber] [name]\n");
            }
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void delWire(String[] consoleComm, ProtoController proto) {
        if (consoleComm.length != 3) {
            print("usage: delete [from Input/Gate output] [name]\n");
            return;
        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1 | proto.nameIsInvalid(consoleComm[2]) == 1) {
            print("Invalid Name\n");
            return;
        }
        Object ob;

        ob = proto.getObjectfromNameBase(consoleComm[1]);
        if (ob.getClass().getName().startsWith("Model.Inputs")) {
            Input inp = (Input) ob;
            try {
                proto.delWire(inp, consoleComm[2]);
                proto.delObjectfromNameBase(consoleComm[2]);
            } catch (Exception ex) {
                Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            if (ob.getClass().getName().startsWith("Model.Gates")) {
                Gate gate = (Gate) ob;
                int outp = 0;
                for (int i = 0; i < gate.getMaxOutput(); i++) {
                    try {
                        if (gate.getWire(i).getName().equals(consoleComm[2])) {
                            outp = i;
                        }
                    } catch (Exception ex) {
                        Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
                try {
                    proto.delWire(gate, outp, consoleComm[2]);
                } catch (Exception ex) {
                    Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
                }
                proto.delObjectfromNameBase(consoleComm[2]);

            } else {
                print("Invalid name");
            }
        }



    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void delete(String[] consoleComm, ProtoController proto) {
        Object ob;
        if (consoleComm.length != 2) {
            print("usage: delete [name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1) {
            print("Invalid Name\n");
            return;
        }
        ob = proto.getObjectfromNameBase(consoleComm[1]);
        print(ob.getClass().getName());
        if (ob.getClass().getName().startsWith("Model.Inputs")) {
            try {
                Input inp = (Input) ob;
                if (inp.getWire() != null) {
                    proto.delWire(inp, inp.getWire().getName());
                    proto.delObjectfromNameBase(inp.getWire().getName());
                }
                proto.delInput(inp);
                proto.delObjectfromNameBase(inp.getName());
            } catch (Exception ex) {
                Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            if (ob.getClass().getName().startsWith("Model.Gates")) {
                Gate gate = (Gate) ob;
                for (int i = 0; i < gate.getMaxOutput(); i++) {
                    try {
                        if (gate.getWire(i) != null) {
                            proto.delWire(gate, i, gate.getWire(i).getName());
                            proto.delObjectfromNameBase(gate.getWire(i).getName());
                        }
                    } catch (Exception ex) {
                        Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                try {
                    proto.delGate(gate);
                    proto.delObjectfromNameBase(gate.getName());
                } catch (Exception ex) {
                    Logger.getLogger(InterCommands.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                print("Invalid name");
            }
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void loadFile(ProtoController proto, String[] consoleComm) {
        if (consoleComm.length != 2) {
            print("usage: loadFile [path]\n");
            return;
        }
        FileInt fi = new FileInt(proto);
        fi.fileinterpret(consoleComm[1]);
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void clean(ProtoController proto, String[] consoleComm) {
        //  System.out.println("clean parancs");
        proto.clear();
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void run(ProtoController proto, String[] consoleComm) {
        // System.out.println("run parancs
        if (consoleComm.length != 2) {
            print("run [Number of steps]");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[1]) < 0) {

                print("run [Number of steps]");

                return;
            }
        } catch (Exception e) {
            print("run [Number of steps]");
            return;
        }
        for (int i = 0; i < Integer.valueOf(consoleComm[1]); i++) {
            proto.runOnce();
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void stop(ProtoController proto, String[] consoleComm) {
        // System.out.println("stop parancs");
        proto.stop();
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void setbutton(String[] consoleComm, ProtoController proto) {
        // print("setButton command");
        Boolean val = false;
        if (consoleComm.length != 3) {
            print("usage: setButton [name] [érték(0/1)] \n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1) {
            print("Invalid Name\n");
            return;
        }
        try {
            if (Integer.valueOf(consoleComm[2]) < 0 | Integer.valueOf(consoleComm[2]) > 1) {
                print("usage: setButton [name] [érték(0/1)] \n");
                return;
            }
        } catch (Exception e) {
            print("usage: setButton [name] [érték(0/1)] \n");
            return;
        }
        try {
            Input but = (Input) proto.getObjectfromNameBase(consoleComm[1]);
            if (Integer.valueOf(consoleComm[2]) == 1) {
                val = true;
            }
            if (Integer.valueOf(consoleComm[2]) == 0) {
                val = false;
            }
            but.setState(val);
        } catch (Exception e) {
            print("Nincs ilyen Button");
            return;
        }




    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void getValue(String[] consoleComm, ProtoController proto) {
        // System.out.println("pause");
        Object ob;
        if (consoleComm.length != 2) {
            print("usage: getValue [name]\n");
            return;

        }
        if (proto.nameIsInvalid(consoleComm[1]) == 1) {
            print("Invalid Name\n");
            return;
        }
        ob = proto.getObjectfromNameBase(consoleComm[1]);
        if (ob.getClass().getName().startsWith("Model.Inputs")) {
            Input inp = (Input) ob;
            proto.getVal(inp);
        } else {
            if (ob.getClass().getName().startsWith("Model.Gates")) {
                Gate gate = (Gate) ob;
                proto.getVal(gate);
            } else {
                print("Bad Command (invalid name)");
            }
        }
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void step(String[] consoleComm, ProtoController proto) {
        //  System.out.println("pause");
        proto.runOnce();
    }

    /**
     *
     * @param proto Protocontroller referencia  
     * @param consolComm A parancs és a paramétereinek string tömbje.
     */
    public static void pause(ProtoController proto, String[] consoleComm) {
        //  System.out.println("pause");
        proto.pause();
    }

    /**
     *
     * @param s Kiírni kívánt string.
     */
    static void print(String s) {
        System.out.print(s);
    }

    /**
     *
     * @param s Kiírni kívánt string.
     */
    static void println(String s) {
        System.out.println(s);
    }
}
